Skip to content

Add server lifecycle audit PowerShell script#47

Open
AlrightLad wants to merge 2 commits intoDTC-Inc:mainfrom
AlrightLad:patch-10
Open

Add server lifecycle audit PowerShell script#47
AlrightLad wants to merge 2 commits intoDTC-Inc:mainfrom
AlrightLad:patch-10

Conversation

@AlrightLad
Copy link

@AlrightLad AlrightLad commented Mar 24, 2026

This script performs a comprehensive audit of server lifecycle aspects including OS details, domain roles, CPU, memory, disk layout, server roles, SQL instances, installed software, running services, file shares, printers, network configuration, DNS settings, DHCP scopes, RDS licensing, scheduled tasks, and Hyper-V VMs.

Summary by CodeRabbit

  • New Features
    • Added a comprehensive Windows server lifecycle audit tool that runs with administrative privileges and produces a timestamped transcript. Generates structured reports covering host and domain details, hardware and storage usage, installed server roles and services, software inventory, network and shared resources, DNS/DHCP/RDS configurations (when available), scheduled tasks, and virtual machines.

This script performs a comprehensive audit of server lifecycle aspects including OS details, domain roles, CPU, memory, disk layout, server roles, SQL instances, installed software, running services, file shares, printers, network configuration, DNS settings, DHCP scopes, RDS licensing, scheduled tasks, and Hyper-V VMs.
@AlrightLad AlrightLad requested a review from Gumbees as a code owner March 24, 2026 07:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb25c2b1-4892-458d-b8e6-6fbd481afda5

📥 Commits

Reviewing files that changed from the base of the PR and between 274fca9 and 517415f.

📒 Files selected for processing (1)
  • msft-windows/msft-windows-vm-lifecycle-audit
🚧 Files skipped from review as they are similar to previous changes (1)
  • msft-windows/msft-windows-vm-lifecycle-audit

📝 Walkthrough

Walkthrough

Added a new PowerShell script Invoke-ServerLifecycleAudit.ps1 that runs a comprehensive server lifecycle audit, collects host/domain/hardware/network/software/role inventories, conditionally queries AD/DNS/DHCP/RDS/Hyper-V components, and writes a transcript log for the audit session.

Changes

Cohort / File(s) Summary
PowerShell Audit Script
msft-windows/msft-windows-vm-lifecycle-audit/Invoke-ServerLifecycleAudit.ps1
New executable PowerShell entrypoint that captures an administrative transcript and outputs structured inventory sections: host OS/domain role, AD FSMO status, CPU/memory/disk, SCSI controllers, Windows features, SQL-related services, installed software (filtered), auto-start non-Microsoft services, non-admin SMB shares/printers, network adapters/IPv4, DNS zones, DHCP v4 scopes, RDS licensing, scheduled tasks, and Hyper-V VMs. Handles RMM vs interactive invocation and conditional cmdlet availability with status messages.

Sequence Diagram(s)

sequenceDiagram
  participant Admin as Admin/Invoker
  participant Script as Invoke-ServerLifecycleAudit.ps1
  participant Host as Local Host OS
  participant AD as Active Directory / netdom
  participant Registry as Uninstall Registry
  participant Services as Windows Services
  participant HyperV as Hyper-V / Get-VM

  Admin->>Script: start (interactive or RMM)
  Script->>Host: start transcript (compute path)
  Script->>Host: gather host OS & domain role
  Script->>AD: query FSMO roles (if netdom)
  Script->>Host: collect CPU, memory, disk, SCSI
  Script->>Services: list auto-start & SQL-related services
  Script->>Registry: enumerate installed software (filtered)
  Script->>Host: list SMB shares, printers, network adapters, IPv4
  Script->>Host: query DNS/DHCP/RDS (conditional cmdlets)
  Script->>HyperV: list VMs (if Get-VM)
  Script->>Host: list scheduled tasks
  Script->>Host: stop transcript
  Script-->>Admin: AUDIT COMPLETE (transcript path)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped in quietly to log each hidden part,

From FSMO peaks to each VM's little heart,
A transcript trail where every secret hides,
I puffed my whiskers, counted cores — and stamped the tides. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add server lifecycle audit PowerShell script' accurately and concisely describes the main change: adding a new PowerShell script for server lifecycle auditing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
msft-windows/msft-windows-vm-lifecycle-audit (1)

1-5: Add transcript logging and an explicit RMM simulation path.

The script currently has no transcript lifecycle, which makes audit traceability harder during field execution and validation.

Proposed logging/testability addition
+# Transcript path under %WINDIR%\logs
+$logDir = Join-Path $env:WINDIR "logs"
+$logFile = Join-Path $logDir ("vm-lifecycle-audit-{0:yyyyMMdd-HHmmss}.log" -f (Get-Date))
+if (-not (Test-Path $logDir)) { New-Item -Path $logDir -ItemType Directory -Force | Out-Null }
+Start-Transcript -Path $logFile -Force
+
+# Optional RMM simulation switch
+$RMM = 0
+# Set $RMM = 1 and predefine required variables during testing
+
 try {
   # existing audit logic...
 }
 finally {
+  Stop-Transcript | Out-Null
 }

Based on learnings: “Verify transcripts/logs in %WINDIR%\logs after execution; support RMM simulation by setting $RMM=1 and predefining required variables during testing”.

Also applies to: 65-65

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@msft-windows/msft-windows-vm-lifecycle-audit` around lines 1 - 5, Add
PowerShell transcript start/stop around the main script execution by invoking
Start-Transcript and Stop-Transcript and write the transcript to
$env:windir\Logs with a timestamped filename so audit traces land in
%WINDIR%\Logs; also add explicit test-mode/RMM simulation support by declaring
and checking a $RMM variable (e.g., default $RMM = 0) and, when $RMM -eq 1,
predefine or mock required input variables and skip any destructive operations
to allow running under RMM testing; ensure Start-Transcript is invoked early
(before major actions) and Stop-Transcript in a finally/cleanup path so
transcripts are always closed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@msft-windows/msft-windows-vm-lifecycle-audit`:
- Around line 1-65: The script lacks the required three-part PowerShell template
(RMM variable declaration, input handling, script logic) so preserve backward
compatibility by adding the RMM variable declaration block and input parsing
before any immediate execution (before the first Write-Host), implement the
input handling/parameter mapping that mirrors script-template-powershell.ps1
(declare expected RMM variables and parse parameters/env), and then move the
existing audit commands into a clearly delimited "script logic" section;
reference the template name script-template-powershell.ps1 and the existing
top-level execution points (the initial Write-Host and subsequent audit command
blocks) to locate where to insert the RMM variables and input handling.
- Around line 12-14: The netdom call in the FSMO block (netdom query fsmo)
currently relies on try/catch which won't catch non-zero exit codes from the
native executable; update the block that calls netdom to capture its output,
examine $LASTEXITCODE immediately after the call, and handle non-zero values by
logging a clear message via Write-Host (including the captured output/error)
instead of silently relying on the catch. Ensure the modified logic still
handles the non-DC case and unavailability of netdom by checking for
$LASTEXITCODE and/or specific error text and emitting a concise failure message.

---

Nitpick comments:
In `@msft-windows/msft-windows-vm-lifecycle-audit`:
- Around line 1-5: Add PowerShell transcript start/stop around the main script
execution by invoking Start-Transcript and Stop-Transcript and write the
transcript to $env:windir\Logs with a timestamped filename so audit traces land
in %WINDIR%\Logs; also add explicit test-mode/RMM simulation support by
declaring and checking a $RMM variable (e.g., default $RMM = 0) and, when $RMM
-eq 1, predefine or mock required input variables and skip any destructive
operations to allow running under RMM testing; ensure Start-Transcript is
invoked early (before major actions) and Stop-Transcript in a finally/cleanup
path so transcripts are always closed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aec60540-d5ba-453e-a146-58ab3c2fd743

📥 Commits

Reviewing files that changed from the base of the PR and between 1ac5146 and 274fca9.

📒 Files selected for processing (1)
  • msft-windows/msft-windows-vm-lifecycle-audit

Updated the server lifecycle audit script to enhance functionality and output formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant